﻿@{
    ViewBag.Title = "Advert";
}
@section scripts
{
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script> 
}

                <div class="mini-toolbar" style="padding:2px;border-top:0;border-left:0;border-right:0;"> 
                    <table style="width:100%;">
                        <tr>
                            <td style="width:100%;">
                                <a class="mini-button" id="fresh" name="fresh" iconCls="icon-search" onclick="search" plain="true">刷新</a>
                                 <span class="separator"></span>
                                <a class="mini-button" id="save" name="save" iconCls="icon-edit" onclick="save" plain="true">保存</a>
                                 <span class="separator"></span>
                                <a class="mini-button" id="adv" name="adv" iconCls="icon-edit" onclick="setAdv" plain="true">批量设置广告</a>
                                 <span class="separator"></span>
                                <a class="mini-button" id="close" name="close" iconCls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
                            </td>
                        </tr>
                    </table>       
                </div>
                    <table>
                        <tr>
                            <td width ="100px" align="right">编码或名称: </td>
                            <td width ="150px" ><input class="mini-textbox" width ="150px" id ="FSearchKey1" name = "FSearchKey1"  onkeypress="setkeyPress()"/></td>
                            <td width ="100px" align="center">
                                <a class="mini-button" iconCls="icon-search" onclick="search" plain="true">查询</a>
                            </td>
                        </tr>
                    </table> 
                <div class="mini-fit" >
                    <div id="datagrid1" class="mini-datagrid" style="width:100%;height:100%;" pageSize="15"
                        borderStyle="border:1;" url="GetListson"
                        allowCellSelect="true" allowCellEdit="true"showColumnsMenu="true"fitColumns="false"  
                        sortMode="client" multiSelect="true">
                        <div property="columns">
                            <div type="checkcolumn" ></div>
                            <div type="indexcolumn" width="40" headerAlign="center" >序号</div>
                            <div field="FNumber" name="FNumber" width="80" headeralign="center" allowsort="true">商户编码</div>
                            <div field="FName" name="FName" width="150" headeralign="center" allowsort="true">商户名称</div>
                            <div field="StockName" name="StockName" width="100" headeralign="center" allowsort="true">默认门店</div>
                            <div field="FAdvUrl" name="FAdvUrl" width="350" headeralign="center" allowsort="true">主屏广告网址
                                <input property="editor" class="mini-textbox" style="width:100%;"/>
                            </div>
                            <div field="FAdvUrlShop" name="FAdvUrlShop" width="350" headeralign="center" allowsort="true">副屏广告网址
                                <input property="editor" class="mini-textbox" style="width:100%;"/>
                            </div>
                            <div field="FAdvUrlFlag" type="checkboxcolumn" name="FAdvUrlFlag" trueValue="1" falseValue="0" width="60" headeralign="center" allowsort="true">是否启用</div> 
                       </div>
                    </div>
               </div>

<script>
    $(function () {
        mini.parse();
        search();
    });
    function search() {
        var json = "[{";
        json = json + "'search':" + "'" + mini.getbyName("FSearchKey1").getValue() + "',";
        json = json + "'mSystemAppID':'"+parent.window.getSystemAppID()+"'}]";
        var grid = mini.get("datagrid1");
        grid.load({ mjson: json });
    }
    function setkeyPress() {
        if(event.keyCode==13)
            search();
    }
    function save() {
        var grid = mini.get("datagrid1");
        var row = grid.getChanges();
        if (row) {
            var json = "[";
            for (var i = 0; i < row.length; i++) {
                if (i > 0) json = json + ',';
                js = '{"FItemID":' + row[i].FItemID + ',"url":"' + row[i].FAdvUrl + '","urlshop":"' + row[i].FAdvUrlShop + '","FAdvUrlFlag":' + row[i].FAdvUrlFlag + '}';
                json = json + js
            }
            json = json + "]";
            $.post("/Corp/saveAdvs", { json: json, mSystemAppID: parent.window.getSystemAppID() }, function (data) {
                var ret = mini.decode(data);
                if (ret.status == 1) {
                    mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                }
                else {
                    mini.alert(ret.error);
                }
                var grid = mini.get("datagrid1");
                grid.reload();
            });
        }
    }
        function setAdv() {
            var grid = mini.get("datagrid1");
            var rows = grid.getSelecteds();
            if (rows.length == 0) {
                mini.alert("请至少选择一项");
                return;
            }
            var json = "[";
            for (var i = 0; i < rows.length; i++) {
                if (i > 0) json = json + ',';
                js = '{"FItemID":' + rows[i].FItemID + '}';
                json = json + js;
            }
            json = json + "]";
            mini.open({
                url: "/Corp/setAdvs",
                title: "批量设置广告", width: 600, height: 200,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = { Json: json, data: grid.getSelected()};
                    iframe.contentWindow.SetInfoData(data);
                },
                ondestroy: function (action) {
                    var grid = mini.get("datagrid1");
                    grid.reload();
                }
            });
        }
</script>
